﻿// Create text on point with specified color
function MapTitle(text, point, offset, opt_color) {  
  this.text_ = text;
  this.point_ = point;  
  this.offset_ = offset;
  this.color_ = opt_color || "#000000";
}

MapTitle.prototype = new GOverlay();

// Creates the DIV representing this MapTitle.
MapTitle.prototype.initialize = function(map) {  
  // Create the DIV representing our MapTitle  
  var div = document.createElement("div");  
    div.style.position = "absolute";
  // Our MapTitle is flat against the map, so we add our selves to the  
  // MAP_PANE pane, which is at the same z-index as the map itself (i.e.,  
  // below the marker shadows)  
  map.getPane(G_MAP_MARKER_SHADOW_PANE).appendChild(div);  
  this.map_ = map;  
  this.div_ = div;
}

// Remove the main DIV from the map pane
MapTitle.prototype.remove = function() {  
  this.div_.parentNode.removeChild(this.div_);
}

// Copy our data to a new MapTitle
MapTitle.prototype.copy = function() {  
  return new MapTitle(this.text_, this.point_, this.color_, this.backgroundColor_, this.opacity_);
}

// Redraw the MapTitle based on the current projection and zoom level
MapTitle.prototype.redraw = function(force) {  
  // We only need to redraw if the coordinate system has changed
  if (!force) return;  
  this.div_.innerHTML = this.text_;
  // set pixel based coordinates from lat/lng
  var leftTop = this.map_.fromLatLngToDivPixel(this.point_);
  leftTop.x = leftTop.x + this.offset_.x;
  leftTop.y = leftTop.y + this.offset_.y;
  this.div_.style.color = this.color_;
  this.div_.style.left =  leftTop.x + "px";  
  this.div_.style.top = leftTop.y + "px";
  this.div_.noWrap = true;
  this.div_.style.width = this.text_.length + "em";
}